#!/bin/sh

if [ $# -ne 0 ]; then 

	echo "usage: $0 "
	exit
fi

source config

#startdate=`find .|grep 001_|sort -g  |head -1| sed -e "s/.*_//" |sed -e "s/日.*\.md//"  |sed -e "s/[年月]/-/g"`

counter=`find .|grep ^$tag|grep md |wc|awk '{print $1}'`

rm -f tmp.1 tmp.2 tmp.3 tmp.4

#echo "creat a empty indexfile"

echo "% "`pwd |awk -F/ '{print $NF}' |sed -e "s/[0123456789]//g"`"@第三同读" > index.md
echo "% hbaolong@vip.qq.com" >>index.md

#echo "link to mingju.html memo.html index_rich.html"

echo "" >> index.md

commcode header >>index.md

commcode bookheader >>index.md

#echo "生成md文件，只包括日。"

ls -R  |grep ^$tag|sort -g |sed -e "s/_/\.html /g" |sed -e "s/ .*月/ /g" | sed -e "s/日.*\.md/日/g" |awk '{print "\["$2 "\](" $1 ")"}'>tmp.1

#echo "按月分行"

cat tmp.1 |sed -e 's/\r//g' |awk '{printf ;printf " "}' | sed -e "s/\[01日/\n\[01日/g" | sed -e "/^$/d">tmp.3

nod $counter $startdate |sed -e "s/月.*/月/"|uniq > tmp.4

paste tmp.4 tmp.3 |sed -e "s/^/\n## /" | sed -e "s/\t/\n\n/g" >>index.md

rm -f tmp.1 tmp.2 tmp.3 tmp.4 
